package org.esprit.ocm.server.metier.common;

import java.util.List;

import org.esprit.ocm.server.dao.common.IDao;

import com.google.gwt.user.client.rpc.RemoteService;

/**
 * Contrat que doit remplir un service par d�faut
 * 
 */ 
public interface ICommonService<T> extends RemoteService {
 
	/**
	 * Get Dao object 
	 * 
	 * @param dao
	 */
	public IDao<T> getDao();

	/**
	 * Return the domain class serviced.
	 * 
	 * @return class The domain class type serviced.
	 */
	public Class<T> getType();

	/**
	 * Expose the setDao method for testing purposes
	 * 
	 * @param dao
	 */
	public void setDao(IDao<T> _dao);

	/**
	 * Generic method to save an object.
	 * 
	 * @param o
	 *            the object to save
	 * @return the object created
	 */
	public T add(T _o);

	/**
	 * Generic method to update an object.
	 * 
	 * @param o
	 *            the object to save
	 * @return the object updated
	 */
	public T save(T _o);

	/**
	 * Generic method to delete an object based on id
	 * 
	 * @param id
	 *            the identifier
	 */
	public void remove(int _id);
	
	/**
	 * Generic method to delete an object
	 * 
	 * @param id
	 *            the identifier
	 */
	public void remove(T _o);

	/**
	 * Generic method used to get total count. Should be used in sequence with
	 * findAll.
	 * 
	 * @return int number of object found
	 */
	public int count();

	/**
	 * Generic method used to get a all objects of a particular type.
	 * 
	 * @return List of populated objects
	 */
	public List<T> fetch();

	/**
	 * Generic method to get an object based on an identifier.
	 * 
	 * @param id
	 *            the identifier (primary key) of the class
	 * @return a populated object
	 */
	public T findById(int _id);

}